<?php

declare(strict_types=1);

namespace App\Controller\Kpi;

use Hyperf\HttpServer\Annotation\AutoController;
use Hyperf\Validation\Annotation\Scene;
use App\Service\SysMenu as SysMenuService;
use App\Request\SysMenuRequest;

#[AutoController]
class SysMenuController extends AbstractController
{
    // 栏目列表
    public function menu_list()
    {
        $result = (new SysMenuService())->menuList([]);
        return $this->returnSuccess($result, '成功');
    }

    // 添加栏目
    #[Scene(scene: 'add', argument: 'request')]
    public function add_menu()
    {
        $params = $this->request->all();
        $data = (new SysMenuService())->addMenu($params);
        return $this->returnSuccess($data, '添加成功');
    }

    // 编辑栏目
    #[Scene(scene: 'edit', argument: 'request')]
    public function edit_menu()
    {
        $params = $this->request->all();
        $data = (new SysMenuService())->editMenu($params['id'], $params);
        return $this->returnSuccess($data, '编辑成功');
    }

    // 删除栏目
    public function delete_menu()
    {
        $id = $this->request->input('id', 0);
        if (!$id)
            return $this->returnError('请求参数错误');
        $data = (new SysMenuService())->deleteMenu($id);
        return $this->returnSuccess($data, '删除成功');
    }
}
